package com.heihei.controller.res;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.heihei.common.page.Query;
import com.heihei.common.response.ResponseVO;
import com.heihei.entity.res.ResTypeEntity;
import com.heihei.service.res.ResTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author duanhengfei
 * @since 2021-11-23
 */
@Api(tags = "资源类型 Controller")
@RestController
@RequestMapping("/res/type")
public class ResTypeController {

    @Resource
    private ResTypeService resTypeService;

    @ApiOperation(value = "添加")
    @PostMapping("/add")
    public ResponseVO<String> add(@RequestBody ResTypeEntity paramEntity) {
        return this.resTypeService.myAdd(paramEntity);
    }

    @ApiOperation(value = "修改")
    @PatchMapping("/update")
    public ResponseVO<Boolean> update(@RequestBody ResTypeEntity paramEntity) {
        return this.resTypeService.myUpdateById(paramEntity);
    }

    @ApiOperation(value = "删除")
    @ApiImplicitParam(name = "id", value = "主键ID", required = true, paramType = "path", dataType = "String")
    @DeleteMapping("/delete/{id}")
    public ResponseVO<Boolean> delete(@PathVariable String id) {
        return this.resTypeService.deleteByIdLogic(id);
    }

    @ApiOperation(value = "批量删除（直接传入一个id数组）")
    @DeleteMapping("/delete-batch")
    public ResponseVO<Boolean> deleteBatch(@RequestBody List<String> idList) {
        return this.resTypeService.deleteBatch(idList);
    }

    @ApiOperation(value = "列表查询（可以根据类型名称模糊检索）")
    @GetMapping("/pageList")
    public ResponseVO<IPage<ResTypeEntity>> list(ResTypeEntity entityParam, Query query) {
        return this.resTypeService.myPageList(entityParam, query);
    }

    @ApiOperation(value = "详情")
    @ApiImplicitParam(name = "id", value = "主键ID", required = true, paramType = "path")
    @GetMapping("/detail/{id}")
    public ResponseVO<ResTypeEntity> detail(@PathVariable String id) {
        return this.resTypeService.myGetById(id);
    }

}
